﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ModelLayer;
using System.Reflection;
using System.Collections.ObjectModel;
using System.IO;
using System.Data.Common;
using System.Data;
namespace ModelAccess
{
    public abstract class AbstractHelper : IDisposable
    {
        public string ERROR_ORIGINATOR = string.Empty;
        public string ERROR_DESCRIPTION = string.Empty;
        public bool ErrorOccurred = false;
        private bool ctxCreata;
        protected assesstoolEntities ctx;
        private string tableName;

        public AbstractHelper(String tableName)
            : base()
        {
         
                ctx = new assesstoolEntities();
                ctxCreata = true;
                this.tableName = tableName;
                

        }
        public DbTransaction startTransaction()
        {
            if (ctx.Connection.State.CompareTo(ConnectionState.Closed) == 0)
                ctx.Connection.Open();
           return ctx.Connection.BeginTransaction();
        }
        public void commit(DbTransaction transaction)
        {
            transaction.Commit();
        }
        public void rollback(DbTransaction transaction)
        {
            transaction.Rollback();
        }
        public AbstractHelper(String tableName,AbstractHelper padre)
            : base()
        {
            ctx = padre.ctx;
            ctxCreata = false;
            this.tableName = tableName;
        }

        public void Dispose()
        {
            if(ctxCreata)
                ctx.Dispose();
        }

       

        
    }
}


